home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Whack-A-Bill / source code / draw.h < prev    next >
Text File  |  1997-09-24  |  10KB  |  393 lines

  1. void LoadImages(void);
  2. void CopyPixels(Rect,Rect);
  3. void DrawFinal(void);
  4. void DrawBackground(void);
  5. void setupGWorld(void);
  6. void DrawPlayers(int drawState, Boolean soundPlayed);
  7.  
  8. CGrafPtr origPort;
  9. GDHandle origDevice;
  10.  
  11. GWorldPtr myOffGWorld;
  12. PixMapHandle offPixMapHandle; 
  13. Rect gWorldRect;
  14.  
  15. GWorldPtr compGWorld;
  16. PixMapHandle offCompPixMapHandle; 
  17.  
  18. GWorldPtr parallaxWorld;
  19. PixMapHandle parallaxPixMapHandle;
  20.  
  21. PicHandle gBackgroundPic;
  22.  
  23.  
  24. typedef struct player
  25.     {
  26.     int score;
  27.     int state;
  28.     char name[8];
  29.     long lastAction;
  30.     }player;
  31.  
  32. player playerOne;
  33. player playerTwo;
  34.  
  35. player **pl1info;
  36. player **pl2info;
  37.  
  38.  
  39. WindowPtr        gScoreWindow;
  40. WindowPtr        gWindowTwo;
  41. WindowPtr        gScreenWindow;
  42. extern WindowPtr        gMainWindow;
  43. Rect            gOffScreenWindowRect;
  44. Rect            gWindowTwoRect;
  45. extern Boolean gatesBlood;
  46. extern Boolean aronBlood;
  47.  
  48. int gParallaxOnePosition,
  49.     gParallaxTwoPosition;
  50.     
  51. Handle soundOne;
  52.  
  53. void LoadImages (void)
  54. {
  55. PicHandle playerOnePict;
  56. PicHandle playerTwoPict;
  57. PicHandle parallaxOnePic;
  58. PicHandle parallaxTwoPic;
  59.  
  60. Rect ImageOneRect;
  61. Rect ImageTwoRect;
  62. Rect parallaxOneRect;
  63. Rect parallaxTwoRect;
  64.  
  65. SetGWorld(myOffGWorld,nil);
  66.  
  67. SetRect(&ImageOneRect,0,0,640,210);
  68. SetRect(&ImageTwoRect,0,210,640,420);
  69. SetRect(¶llaxOneRect,0,0,801,210);
  70. SetRect(¶llaxTwoRect,0,210,801,420);
  71.  
  72. if(aronBlood)
  73. playerOnePict=GetPicture(668);
  74. else
  75. playerOnePict=GetPicture(667);
  76.  
  77. if(gatesBlood)
  78. playerTwoPict=GetPicture(14);
  79. else
  80. playerTwoPict=GetPicture(13);
  81.  
  82.  
  83. parallaxOnePic=GetPicture(251);
  84. parallaxTwoPic=GetPicture(250);
  85.  
  86. DrawPicture(playerOnePict,&ImageOneRect);
  87. DrawPicture(playerTwoPict,&ImageTwoRect);
  88.  
  89. SetGWorld(parallaxWorld,nil);
  90. DrawPicture(parallaxOnePic,¶llaxOneRect);
  91. DrawPicture(parallaxTwoPic,¶llaxTwoRect);
  92. }
  93.  
  94. void CopyPixels(Rect sourceRect,Rect destRect)
  95. {
  96.  
  97. RGBColor background;
  98.  
  99. background.red=0;
  100. background.blue=65535;
  101. background.green=65535;
  102. RGBBackColor(&background);    
  103.  
  104. SetGWorld(compGWorld,nil); 
  105. CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits, 
  106.           &sourceRect, &destRect, transparent, nil );
  107. }
  108.  
  109. void DrawFinal(void)
  110. {
  111. Rect compRect,
  112.      outRect;
  113. RGBColor background;
  114.  
  115. background.red=0;
  116. background.blue=65535;
  117. background.green=65535;
  118. RGBBackColor(&background);    
  119.  
  120. SetRect(&compRect,0,0,320,210);
  121. SetRect(&outRect,0,0,320,210);
  122.  
  123. SetGWorld(origPort,origDevice);  
  124. CopyBits (&((GrafPort*)compGWorld)->portBits,&((GrafPort*)gWindowTwo)->portBits, 
  125.           &compRect, &outRect, transparent, nil ); 
  126. }
  127.  
  128. void DrawBackground(void)
  129. {
  130. Rect parallaxOneRect,
  131.      parallaxTwoRect,
  132.      backgroundRect,
  133.      destRect,
  134.      sourceRect;
  135. RGBColor background;
  136.  
  137.  
  138. background.red=0;
  139. background.blue=65535;
  140. background.green=65535;
  141. RGBBackColor(&background);    
  142.  
  143.  
  144. SetRect(&backgroundRect,0,0,320,210);
  145. SetRect(¶llaxOneRect,0,0,320,210);
  146. SetRect(¶llaxTwoRect,0,210,320,420);
  147.  
  148.  
  149. SetGWorld(compGWorld,nil); 
  150.  
  151. //Calculate Positions and Draw Images to Offscreen World
  152. if (gParallaxOnePosition < 801-320)
  153.     {    
  154.     parallaxOneRect.left = parallaxOneRect.left+gParallaxOnePosition;
  155.     parallaxOneRect.right = parallaxOneRect.right+gParallaxOnePosition;
  156.     CopyBits (&((GrafPort*)parallaxWorld)->portBits,&((GrafPort*)compGWorld)->portBits, 
  157.     ¶llaxOneRect, &backgroundRect, transparent, nil );
  158.     }
  159. else
  160. {
  161. sourceRect.left=gParallaxOnePosition;
  162. sourceRect.right=801;
  163. sourceRect.top=0;
  164. sourceRect.bottom=210;
  165. destRect.left=0;
  166. destRect.right=(801-gParallaxOnePosition);
  167. destRect.top=0;
  168. destRect.bottom=210;
  169.  
  170. CopyBits (&((GrafPort*)parallaxWorld)->portBits,&((GrafPort*)compGWorld)->portBits, 
  171.             &sourceRect, &destRect, transparent, nil );
  172.  
  173. sourceRect.left=0;
  174. sourceRect.right=(320-801+gParallaxOnePosition);
  175. sourceRect.top=0;
  176. sourceRect.bottom=210;
  177. destRect.left=(801-gParallaxOnePosition);
  178. destRect.right=(320);
  179. destRect.top=0;
  180. destRect.bottom=210;
  181.  
  182. CopyBits (&((GrafPort*)parallaxWorld)->portBits,&((GrafPort*)compGWorld)->portBits, 
  183.             &sourceRect, &destRect, transparent, nil );
  184. }
  185.  
  186. if (gParallaxTwoPosition < 801-320)
  187.     {
  188.     parallaxTwoRect.left = parallaxTwoRect.left+gParallaxTwoPosition;
  189.     parallaxTwoRect.right = parallaxTwoRect.right+gParallaxTwoPosition;
  190.     CopyBits (&((GrafPort*)parallaxWorld)->portBits,&((GrafPort*)compGWorld)->portBits, 
  191.     ¶llaxTwoRect, &backgroundRect, transparent, nil );
  192.     }
  193. else
  194. {
  195. sourceRect.left=gParallaxTwoPosition;
  196. sourceRect.right=801;
  197. sourceRect.top=210;
  198. sourceRect.bottom=420;
  199. destRect.left=0;
  200. destRect.right=(801-gParallaxTwoPosition);
  201. destRect.top=0;
  202. destRect.bottom=210;
  203.  
  204. CopyBits (&((GrafPort*)parallaxWorld)->portBits,&((GrafPort*)compGWorld)->portBits, 
  205.             &sourceRect, &destRect, transparent, nil );
  206.  
  207. sourceRect.left=0;
  208. sourceRect.right=(320-801+gParallaxTwoPosition);
  209. sourceRect.top=210;
  210. sourceRect.bottom=420;
  211. destRect.left=(801-gParallaxTwoPosition);
  212. destRect.right=(320);
  213. destRect.top=0;
  214. destRect.bottom=210;
  215.  
  216. CopyBits (&((GrafPort*)parallaxWorld)->portBits,&((GrafPort*)compGWorld)->portBits, 
  217.             &sourceRect, &destRect, transparent, nil );
  218. }
  219.  
  220.  
  221. //move Parallax Positions
  222. gParallaxOnePosition = gParallaxOnePosition + 3;
  223. gParallaxTwoPosition = gParallaxTwoPosition + 8;
  224.  
  225. if (gParallaxOnePosition > 801)
  226.     gParallaxOnePosition = (gParallaxOnePosition - 801);
  227.     
  228. if (gParallaxTwoPosition > 801)
  229.     gParallaxTwoPosition = (gParallaxTwoPosition - 801);
  230. }
  231.  
  232. void setupGWorld(void)
  233. {
  234. Rect compGWorldRect;
  235. Rect parallaxWorldRect;
  236.  
  237. SetRect(&gWorldRect,0,0,640,420);
  238. SetRect(&compGWorldRect,0,0,360,240);
  239. SetRect(¶llaxWorldRect,0,0,801,420);
  240.  
  241. GetGWorld(&origPort,&origDevice);
  242.  
  243. NewGWorld(&myOffGWorld,0,&gWorldRect,nil,nil,0);
  244. SetGWorld(myOffGWorld,nil);
  245. offPixMapHandle = GetGWorldPixMap(myOffGWorld);
  246. LockPixels(offPixMapHandle);
  247. EraseRect(&myOffGWorld->portRect);
  248.  
  249. NewGWorld(&compGWorld,0,&compGWorldRect,nil,nil,0);
  250. SetGWorld(compGWorld,nil);
  251. offPixMapHandle = GetGWorldPixMap(compGWorld);
  252. LockPixels(offCompPixMapHandle);
  253. EraseRect(&compGWorld->portRect);
  254.  
  255. NewGWorld(¶llaxWorld,0,¶llaxWorldRect,nil,nil,0);
  256. SetGWorld(parallaxWorld,nil);
  257. offPixMapHandle = GetGWorldPixMap(parallaxWorld);
  258. LockPixels(parallaxPixMapHandle);
  259. EraseRect(¶llaxWorld->portRect);
  260. }
  261.  
  262. void DrawPlayers(int drawState, Boolean soundPlayed)
  263. {
  264. Rect sourceRect,
  265.      destRect;
  266. RGBColor background;
  267.  
  268. background.red=0;
  269. background.blue=65535;
  270. background.green=65535;
  271. RGBBackColor(&background);    
  272.  
  273.  
  274. switch(drawState)
  275. {
  276. case 1:
  277. //player One Hits
  278.     SetRect(&sourceRect,0,210,320,420);
  279.     SetRect(&destRect,0,0,320,210);
  280.     SetGWorld(compGWorld,nil); 
  281.     CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits, 
  282.           &sourceRect, &destRect, transparent, nil );
  283.  
  284. //Player Two Gets Hit
  285.     SetRect(&sourceRect,160,0,320,210);
  286.     SetRect(&destRect,160,0,320,210);
  287.     SetGWorld(compGWorld,nil); 
  288.     CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits, 
  289.           &sourceRect, &destRect, transparent, nil );
  290.  
  291.     break;
  292. case 2:
  293. // Player Two Duck
  294.     SetRect(&sourceRect,0,0,160,127);
  295.     SetRect(&destRect,160,83,320,210);
  296.     SetGWorld(compGWorld,nil); 
  297.     CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits, 
  298.           &sourceRect, &destRect, transparent, nil );
  299. //player One Hits
  300.     SetRect(&sourceRect,0,210,320,420);
  301.     SetRect(&destRect,0,0,320,210);
  302.     SetGWorld(compGWorld,nil); 
  303.     CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits, 
  304.           &sourceRect, &destRect, transparent, nil );
  305.     break;
  306. case 3:
  307. //Player One Gets Hit
  308.     SetRect(&sourceRect,320,210,480,420);
  309.     SetRect(&destRect,0,0,160,210);
  310.     SetGWorld(compGWorld,nil); 
  311.     CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits, 
  312.           &sourceRect, &destRect, transparent, nil );
  313.  
  314. //player Two Hits
  315.     SetRect(&sourceRect,320,0,640,210);
  316.     SetRect(&destRect,0,0,320,210);
  317.     SetGWorld(compGWorld,nil); 
  318.     CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits, 
  319.           &sourceRect, &destRect, transparent, nil );
  320.     break;
  321. case 4:
  322. // Player One Normal
  323.     SetRect(&sourceRect,480,210,640,420);
  324.     SetRect(&destRect,0,0,160,210);
  325.     SetGWorld(compGWorld,nil); 
  326.     CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits, 
  327.           &sourceRect, &destRect, transparent, nil );
  328. // Player Two Normal
  329.     SetRect(&sourceRect,0,0,160,210);
  330.     SetRect(&destRect,160,0,320,210);
  331.     SetGWorld(compGWorld,nil); 
  332.     CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits, 
  333.           &sourceRect, &destRect, transparent, nil );
  334.     break;
  335. case 5:
  336. // Player Two Duck
  337.     SetRect(&sourceRect,0,0,160,127);
  338.     SetRect(&destRect,160,83,320,210);
  339.     SetGWorld(compGWorld,nil); 
  340.     CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits, 
  341.           &sourceRect, &destRect, transparent, nil );
  342. // Player One Normal
  343.     SetRect(&sourceRect,480,210,640,420);
  344.     SetRect(&destRect,0,0,160,210);
  345.     SetGWorld(compGWorld,nil); 
  346.     CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits, 
  347.           &sourceRect, &destRect, transparent, nil );
  348.     break;
  349. case 6:
  350. // Player One Duck
  351.     SetRect(&sourceRect,480,210,640,337);
  352.     SetRect(&destRect,0,83,160,210);
  353.     SetGWorld(compGWorld,nil); 
  354.     CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits, 
  355.           &sourceRect, &destRect, transparent, nil );
  356. //player Two Hits
  357.     SetRect(&sourceRect,320,0,640,210);
  358.     SetRect(&destRect,0,0,320,210);
  359.     SetGWorld(compGWorld,nil); 
  360.     CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits, 
  361.           &sourceRect, &destRect, transparent, nil );
  362.     break;
  363. case 7:
  364. // Player One Duck
  365.     SetRect(&sourceRect,480,210,640,337);
  366.     SetRect(&destRect,0,83,160,210);
  367.     SetGWorld(compGWorld,nil); 
  368.     CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits, 
  369.           &sourceRect, &destRect, transparent, nil );
  370.     // Player Two Normal
  371.     SetRect(&sourceRect,0,0,160,210);
  372.     SetRect(&destRect,160,0,320,210);
  373.     SetGWorld(compGWorld,nil); 
  374.     CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits, 
  375.           &sourceRect, &destRect, transparent, nil );
  376.     break;
  377. case 8:
  378. // Player One Duck
  379.     SetRect(&sourceRect,480,210,640,337);
  380.     SetRect(&destRect,0,83,160,210);
  381.     SetGWorld(compGWorld,nil); 
  382.     CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits, 
  383.           &sourceRect, &destRect, transparent, nil );
  384. // Player Two Duck
  385.     SetRect(&sourceRect,0,0,160,127);
  386.     SetRect(&destRect,160,83,320,210);
  387.     SetGWorld(compGWorld,nil); 
  388.     CopyBits (&((GrafPort*)myOffGWorld)->portBits,&((GrafPort*)compGWorld)->portBits, 
  389.           &sourceRect, &destRect, transparent, nil );
  390.  
  391.     break;
  392.     }
  393. }